<?php
use Phalcon\Http\Response;

class CommentController extends ControllerBase
{

    public function indexAction($object,$object_id)
    {
    	$result = Comment::find("object = '$object' AND object_id = $object_id AND is_visible = 1 AND is_delete = 0")->toArray();
    	echo json_encode(["error"=>false,"data"=>$result]);
    	$this->view->disable();
    }

    public function storeAction($object,$object_id)
    {
    	$request = $_REQUEST;
    	$data = [
    		"object" 		=>$object,
    		"object_id" 	=>$object_id,
    		"father_id" 	=>$request['father_id'],
    		"content"		=>$request['content']
    	];
    	$model = new Comment();
        $result = $model->save($data);
    	echo json_encode(["error"=>false,"data"=>$result]);
    	$this->view->disable();	
    }

    public function destroyAction($object,$object_id,$comment_id)
    {
    	$model = new Comment();
    	$result = $model->findFirst("object = '$object' AND object_id = $object_id AND id = $comment_id")->delete();
    	echo json_encode(["error"=>false,"data"=>$result]);
    	$this->view->disable();
    }
}